import flash.display.BitmapData;

/** Holds map information */
class Terrain {

    public static var SKY = 0xBBCCEE;
    public static var EARTH1 = 0x885533;
    public static var EARTH2 = 0x774422;

    var raster: BitmapData;

    public function new(w: Int, h: Int) {
        raster = new BitmapData(w, h);
        
        generate(raster);
    }

    function generate(bitmap: BitmapData) {
        var horizon = bitmap.height / 4.0;
        for (y in 0...bitmap.height) {
            for (x in 0...bitmap.width) {
           
                var color = if (y < horizon) SKY else (if (Math.random() < 0.4) EARTH1 else EARTH2);

                bitmap.setPixel(x, y, color);
            }        
        }        
    }

    public function render(x: Int, y: Int) {
        var mc: flash.display.MovieClip = flash.Lib.current;
        mc.graphics.beginBitmapFill(raster);
        mc.graphics.drawRect(0, 0, raster.width, raster.height);
        mc.graphics.endFill();
    }
    

}
